import { nodeTree } from "./node_tree";

/** 提示模板 */
const dontSelectCorrectAssetMsg: Editor.Dialog.MessageDialogOptions = {
	title: "Prefab导出提示",
	buttons: ["确定"],
	default: 0
};
/**
 * @en
 * @zh 为扩展的主进程的注册方法
 */
export const methods: { [key: string]: (...any: any) => any } = {
	async generate() {
		let currentSelection = Editor.Selection.getSelected("node");
		// console.log("urls=====", currentSelection);
		if (currentSelection.length <= 0) {
			Editor.Dialog.warn("Please select a UI prefab!", dontSelectCorrectAssetMsg);
			return;
		}
		// console.log(currentSelection);

		let selectionUUid = currentSelection[0];
		let assetInfo = await Editor.Message.request("scene", "query-node-tree", selectionUUid);
		// console.log(assetInfo);

		selectionUUid = assetInfo.prefab.assetUuid;
		assetInfo = await Editor.Message.request("asset-db", "query-asset-info", selectionUUid); //assetInfoByUuid(selectionUUid);
		// console.log(assetInfo);
		let assetType = assetInfo!.type;
		if (assetInfo && assetType === "cc.Prefab") {
			nodeTree.dealPrefab(assetInfo!);
		} else {
			Editor.Dialog.warn("Please select a UI prefab!", dontSelectCorrectAssetMsg);
		}
	}
};

/**
 * @en Hooks triggered after extension loading is complete
 * @zh 扩展加载完成后触发的钩子
 */
export const load = function () {
	nodeTree.init();
};

/**
 * @en Hooks triggered after extension uninstallation is complete
 * @zh 扩展卸载完成后触发的钩子
 */
export const unload = function () {};
